  
  my $bpe_begin = 0x24590;
  my $bpe_end = 0x7c1e8;
  my $bpe_size = ($bpe_end - $bpe_begin)/8+1;
  my @bpe_stat = (0) x $bpe_size;
  
  use constant {
    PPCADDR_PAGETABLE_AREA => 0xf0000000,
    PPCADDR_DRAM_NC        => 0x88000000,
    MM_PAGEMASK            => 0xC0000000,
    MM_PS1                 => 0x00000000,
    MM_PS8                 => 0x40000000,
    MM_MMUMASK             => 0x3FFFFFFF,
    MM_INDEXPS1            => 0x00000000,
    MM_INDEXPS8            => 0x00000003,
    DRAM_COPYENGINE_AREA   => 0x00100000,
    SIZE_COPYENGINE_AREA   => 0x00040000
  };

  sub Adr_rTableToPpc {
    my $rTable = shift;
    if( ($rTable & MM_PAGEMASK) == MM_PS8 ) {
      return (PPCADDR_PAGETABLE_AREA + (($rTable & MM_MMUMASK)>>MM_INDEXPS8)*4);
    } elsif( ($rTable & MM_PAGEMASK) == MM_PS1 ) {
      return (PPCADDR_PAGETABLE_AREA + (($rTable & MM_MMUMASK)>>MM_INDEXPS1)*4);
    }
    return 0;
  }

  sub Adr_DramToPpc {
    my $DramAddr = shift;
    return $DramAddr + PPCADDR_DRAM_NC;
  }

  sub analyze_pagetable {
    my $ptaddr = shift;
    my $pagesize = shift;
    my $inc = shift;

    for( my $i = 0; $i < $pagesize; $i++ ) {
      my $entry = Dmp_Iu32AtPpc($ptaddr + $i*4);
      if( $entry >= $bpe_begin && $entry <= $bpe_end
          && ($entry % 8) == 0 ) {
        my $index = ($entry-$bpe_begin)>>3;
        $bpe_stat[$index] += $inc;
      }
    }
  }
  
  sub analyze_free_pagetable {
    my ($start, $end, $pagesize) = @_;
    for(my $i = 0; $start + $i*4 < $end; $i++) {
      my $pt = Dmp_Iu32AtPpc($start + $i*4);
      my $pt_addr = Adr_rTableToPpc($pt);
      #printf("pt = 0x%08x, pt_addr = 0x%08x\n", $pt, $pt_addr);
      analyze_pagetable($pt_addr, $pagesize, -1);
    }
  }
  
  analyze_pagetable(0xf0000000, 0x4c0000/4, 1);

  my ($stack, $start, $end);
  $stack = Sym_SymToAddr("Knl_PageTableStack");
  $end = Dmp_Iu32AtPpc($stack);
  $start = Dmp_Iu32AtPpc($stack + 4);
  printf("%08lx, %08lx, %08lx\n", $stack, $start, $end);
  analyze_free_pagetable($start, $end, 64);

  $stack = Sym_SymToAddr("Knl_MPageTableStack");
  $end = Dmp_Iu32AtPpc($stack);
  $start = Dmp_Iu32AtPpc($stack + 4);
  printf("%08lx, %08lx, %08lx\n", $stack, $start, $end);
  analyze_free_pagetable($start, $end, 1024);

  $stack = Sym_SymToAddr("LocalADDL0");
  $start = Adr_DramToPpc(Dmp_Iu32AtPpc($stack));
  $end = Adr_DramToPpc(DRAM_COPYENGINE_AREA + SIZE_COPYENGINE_AREA);
  printf("%08lx, %08lx, %08lx\n", $stack, $start, $end);
  analyze_pagetable($start, ($end - $start)/4, 1);  

  my $count=0;
  for( my $i = 0; $i < $bpe_size; $i++ ) {
    if( $bpe_stat[$i] == 0 ) {
      printf("0x%08x\n", $i*8 + $bpe_begin);
      $count++;
    }
  }
  print "$count/$bpe_size\n";
